﻿var trunPageObj;//翻页组件对像
$(initPage);
function initPage() {
//	var date = new Date();
//	date.setDate(date.getDate() - 1);
//	//日期默认为昨天
//	$("#operDate").val($.formatDate(date, "yyyy-MM-dd"));
	//初始化翻页组件
    trunPageObj =  $(".pageNext").turnPage(12, exportList);
    
	$("#queryLog").click(function() {
		$("#log_list").empty();
		trunPageObj.gotoPage(1);//搜索第一页
	});
	trunPageObj.gotoPage(1);//搜索第一页
}

function queryList() {
	var operDate = $("#operDate").val();
	var etlProcID = $("#etlProcID").val();
	var prepLevelID = $("#prepLevelID").val();
	var pageno=trunPageObj.getCurrentPageNo();//当前第几页
	var pagecount=trunPageObj.getPageCount();//一页多少条
	$.post("m/etl_log/query_run", {
		pageNo: pageno,
		pageSize : pagecount,
		operDate:operDate,
		etlProcID:etlProcID,
		prepLevelID:prepLevelID
	}, function(data) {
		if ($.checkErrorMsg(data) ) {
			var fileList = "";
			if(data.etlLogPage && data.etlLogPage.dataList){
				var dataList = data.etlLogPage.dataList;
				$(dataList).each(function(i) {
					var runStatus = dataList[i].runStatus;
					var status = runStatus == 1 ? "开始" : (runStatus == 2 ? "成功" : "失败");
					var color;
					if (dataList[i].prepLevelID == "1") {
						color = 'red';
					} else if (dataList[i].prepLevelID == "2") {
						color = 'blue';
					} else {
						color = 'black';
					}
					fileList += "<tr class='table_td_font' bgColor='#ffffff' style='color:" + color + "'>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + (i + 1) + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].prepLevelText + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].formatOperDate + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].formatOperTime + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" + dataList[i].etlProcText + "</td>";
					fileList += "<td align='center'  height='25px' class='queryList_linebg' nowrap>" +  status + "</td>";
					fileList += "<td align='left'  height='25px' class='queryList_linebg' nowrap>" + (dataList[i].resultMsg ? dataList[i].resultMsg:"") + "</td>";
					fileList += "</tr>";
				});
			}
			$("#log_list").html(fileList);
			trunPageObj.setPageData(data.etlLogPage);
		} 
	}, "json");
}

function exportList() {
	var obj = window.showModalDialog(BASE_PATH + "page/export_select.jsp","","dialogWidth:200px;dialogHeight:80px;help:no;center:yes;status:no");
	if (obj) {
		window.open("m/etl_log/exportrunlog?operDate=" + $.trim($("#operDate").val()) + "&etlProcID=" + $.trim($("#etlProcID").val()) + "&prepLevelID=" + $.trim($("#prepLevelID").val()) + "&expType=" + obj);
	}
}